[#include "/includes/_layout.html"/]
[#macro css]
<style type="text/css">
a:link {
 text-decoration: none;
}
a:visited {
 text-decoration: none;
}
a:hover {
 text-decoration: none;
}
a:active {
 text-decoration: none;
}
 .app-image-list li {
    background-color: #fff;
    border: 1px solid #ddd;
    display: block;
    float: left;
    height: 40px;
    position: relative;
    width: 40px;
}
.app-image-list li img {
    height: 100%;
    width: 100%;
}

.goods-title {
    max-height: 40px;
    overflow: hidden;
    word-break: break-all;
}

.nav-tabs li{width:100px;}
.nav-tabs li a{text-align: center;}
</style>
[/#macro]
<script type="text/javascript">
function addGoods(){
	location.href=obz.ctx + "/product/add";
}
$(document).ready(function() {
	searchProducts();
});
var pageClick = function(pageNo) {
	searchProducts(pageNo);
}

var searchProducts = function(currPage){
	var params = {};
	//其他查询条件
	if(currPage){
		params.page = currPage;
	}
	//params.qname = qname;
	//params.type = $("#a_type_sel").val();
	//params.status = $("#a_status_sel").val();
	
	$("#mainTable").mask("加载中...");
	var url = obz.ctx + "/product/warehouse";
	obz.ajaxJson(url, params, function(resp){
		$("#mainTable").unmask();
		var result = resp.data;
		$(".productLotGrid").empty();
		if(currPage){
			$("#pager").pager({ pagenumber:currPage, recordcount:result.totalRow, pagesize:result.pageSize, recordtext:'共 {0} 页, {1} 条记录', buttonClickCallback: pageClick });
		}else{
			$("#pager").pager({ recordcount:result.totalRow, pagesize:result.pageSize, recordtext:'共 {0} 页, {1} 条记录', buttonClickCallback: pageClick });	
		}
		var dataList = result.list;
		if(dataList.length>0){
			for(var i=0;i<dataList.length;i++){
				var _row = dataList[i];
				var trHtml = obz.dataTemplate4obj($("#product_table_tr_tpl").html(), _row);
				$(".productLotGrid").append(trHtml);
			}
			TBatch.checkCheckbox();
			TBatch.initCheckboxClick();
			TBatch.initOptEvent(ActivityTableOpt.init());
		}else{
			$(".productLotGrid").append($("#table_noresult_tr_tpl").html());
		}
	});
}

//=============================表格操作事件开始=============================================
var ActivityTableOpt = {
	edit : function(param){
		var id = param[1];
		location.href = obz.ctx + "/product/edit/"+id;
	}, 
	
	del : function(param){
		obz.showMessage("确定上架吗？", function(){
			var ids = param[1];
    		obz.ajaxJson(obz.ctx + "/product/shelve", {ids: ids}, function(resp){
    			if(resp.code==200){
    				searchProducts();	
    			}
    		});
		});
		return false;
	},
 
	
	init : function(){
		var optArray = new Array();
		optArray.push(this.edit);
		optArray.push(this.del);
		return optArray;
	}
}	
//=============================表格操作事件结束=============================================
</script>
</head>
<body class="fixed-sidebar full-height-layout gray-bg">
[@layout]
<div class="wrapper wrapper-content">
	
	<div class="row animated fadeInLeft">
	
	[#include "/includes/menu-product.html" /]
	
	<div class="col-sm-11">
		<div class="row content-tabs">
	        <nav class="page-tabs J_menuTabs">
	        	<div class="page-tabs-content" style="margin-left: 0px;">
	        	<a href="${webctx}/product" class="J_menuTab">出售中</a>
	            <a href="${webctx}/product/warehouseIndex" class="J_menuTab active">仓库中</a>
	        	</div>
	        </nav>
	    </div>
		<div id="tableList" class="row ibox-content">
		<div class="panel-body"><button onclick="addGoods();" class="btn btn-success">发布商品</button></div>
		<table class="table table-striped table-bordered bootstrap-datatable datatable" id="mainTable" border="0">
			<thead>
				<tr>
					<th><input type="checkbox" id="all" title="全选/反选" style="margin-right: 4px; vertical-align: middle;"/></th>
					<th><span style="vertical-align: middle;">&nbsp;&nbsp;商品</span></th>
					<th>价格</th>
					<th>库存</th>
					<th>创建时间</th>
					<th>销量</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody class="productLotGrid">
			</tbody>
		</table>
		<div id="productToolsbar" class="panel-body">
			<div id="pager" class="jqpager" style="margin-bottom: 1px;float: right;"></div>
		</div>
		</div>
	</div>
	</div>
</div>

<script type="text/template" id="product_table_tr_tpl">
		<tr class="package">
			<td>
				<input type="checkbox" class="commchk" id="checkbox_{id}" style="margin-right: 4px; vertical-align: middle;"/>
			</td>
			<td>
			<ul class="js-picture-lists app-image-list"><li><img src="{img}"></li></ul>
            <p class="goods-title"><a class="new-window" href="javascript:void(0)"  title="{name}">{name}</a></p>
			</td>
			<td><span class="label label-success">￥{price}</span></td>
            <td>{stock}</td>
            <td><span>{startDate}</span></td>
            <td>{sales}</td>
			<td>
				&nbsp;<a id="edit_{id}" href="javascript:void(0)">编辑</a>
				&nbsp;<a id="del_{id}" href="javascript:void(0)">上架</a>
			</td>
		</tr>
</script>
<script type="text/template" id="table_noresult_tr_tpl">
	<tr class="package"><td class="center" colspan="7">还没有下架的商品</td></tr>
</script>
[/@layout]
<script>
Template.init("#menu-goods");
Template.initSecond("#menu-product-secd");
</script>
</body>
</html>